﻿using System.Linq;
using TMT_CMS.BL.DB;
using TMT_CMS.BL.Model;
using TMT_CMS.BL.Model.BasicData;
using TMT_CMS.BL.Utility;

namespace TMT_CMS.BL
{
    public static class BasicDataManager
    {
        /// <summary>
        /// 国家表
        /// </summary>
        /// <param name="paggingModel"></param>
        /// <returns></returns>
        public static PaggingResultModel<CountryInfo, BasicDataSearchModel> GetCountryList(PaggingRequestModel paggingModel)
        {
            TMT_VENDOR vendor = new TMT_VENDOR();
            try
            {
                vendor.Connection.Open();

                var query = (from country in vendor.CountryInfo select country);

                query = query.OrderBy(q => q.ID);

                return DBUtility.BuildPaggingResult<CountryInfo, BasicDataSearchModel>(query, paggingModel, null);
            }
            finally
            {
                vendor.Connection.Close();
            }
        }


        /// <summary>
        /// 省份表
        /// </summary>
        /// <param name="paggingModel"></param>
        /// <returns></returns>
        public static PaggingResultModel<ProvinceInfo, BasicDataSearchModel> GetProvinceList(PaggingRequestModel paggingModel)
        {
            TMT_VENDOR vendor = new TMT_VENDOR();
            try
            {
                vendor.Connection.Open();

                var query = (from province in vendor.ProvinceInfo select province);

                query = query.OrderBy(q => q.ID);

                return DBUtility.BuildPaggingResult<ProvinceInfo, BasicDataSearchModel>(query, paggingModel, null);
            }
            finally
            {
                vendor.Connection.Close();
            }
        }

        /// <summary>
        /// 城市列表
        /// </summary>
        /// <param name="paggingModel"></param>
        /// <returns></returns>
        public static PaggingResultModel<CityInfo, BasicDataSearchModel> GetCityList(PaggingRequestModel paggingModel)
        {
            TMT_VENDOR vendor = new TMT_VENDOR();
            try
            {
                vendor.Connection.Open();

                var query = (from city in vendor.CityInfo select city);

                query = query.OrderBy(q => q.ID);

                return DBUtility.BuildPaggingResult<CityInfo, BasicDataSearchModel>(query, paggingModel, null);
            }
            finally
            {
                vendor.Connection.Close();
            }
        }



        /// <summary>
        /// 地点表
        /// </summary>
        /// <param name="paggingModel"></param>
        /// <returns></returns>
        public static PaggingResultModel<LocationInfo, BasicDataSearchModel> GetLocationList(PaggingRequestModel paggingModel)
        {
            TMT_VENDOR vendor = new TMT_VENDOR();
            try
            {
                vendor.Connection.Open();

                var query = (from location in vendor.LocationInfo select location);

                query = query.OrderBy(q => q.ID);

                return DBUtility.BuildPaggingResult<LocationInfo, BasicDataSearchModel>(query, paggingModel, null);
            }
            finally
            {
                vendor.Connection.Close();
            }
        }

        /// <summary>
        /// 币种
        /// </summary>
        /// <param name="paggingModel"></param>
        /// <returns></returns>
        public static PaggingResultModel<CurrencyType, BasicDataSearchModel> GetCurrencyTypeList(PaggingRequestModel paggingModel)
        {
            TMT_VENDOR vendor = new TMT_VENDOR();
            try
            {
                vendor.Connection.Open();

                var query = (from currencyType in vendor.CurrencyType select currencyType);

                query = query.OrderBy(q => q.ID);

                return DBUtility.BuildPaggingResult<CurrencyType, BasicDataSearchModel>(query, paggingModel, null);
            }
            finally
            {
                vendor.Connection.Close();
            }
        }

        /// <summary>
        /// 费用类型
        /// </summary>
        /// <param name="paggingModel"></param>
        /// <returns></returns>
        public static PaggingResultModel<FeeType, BasicDataSearchModel> GetFeeTypeList(PaggingRequestModel paggingModel)
        {
            TMT_VENDOR vendor = new TMT_VENDOR();
            try
            {
                vendor.Connection.Open();

                var query = (from feeType in vendor.FeeType select feeType);

                query = query.OrderBy(q => q.ID);

                return DBUtility.BuildPaggingResult<FeeType, BasicDataSearchModel>(query, paggingModel, null);
            }
            finally
            {
                vendor.Connection.Close();
            }
        }

        /// <summary>
        /// 服务类型
        /// </summary>
        /// <param name="paggingModel"></param>
        /// <returns></returns>
        public static PaggingResultModel<ServiceType, BasicDataSearchModel> GetServiceTypeList(PaggingRequestModel paggingModel)
        {
            TMT_VENDOR vendor = new TMT_VENDOR();
            try
            {
                vendor.Connection.Open();

                var query = (from service in vendor.ServiceType select service);

                query = query.OrderBy(q => q.ID);

                return DBUtility.BuildPaggingResult<ServiceType, BasicDataSearchModel>(query, paggingModel, null);
            }
            finally
            {
                vendor.Connection.Close();
            }
        }


        /// <summary>
        /// 业务类型
        /// </summary>
        /// <param name="paggingModel"></param>
        /// <returns></returns>
        public static PaggingResultModel<BusinessType, BasicDataSearchModel> GetBusinessTypeList(PaggingRequestModel paggingModel)
        {
            TMT_VENDOR vendor = new TMT_VENDOR();
            try
            {
                vendor.Connection.Open();

                var query = (from business in vendor.BusinessType select business);

                query = query.OrderBy(q => q.ID);

                return DBUtility.BuildPaggingResult<BusinessType, BasicDataSearchModel>(query, paggingModel, null);
            }
            finally
            {
                vendor.Connection.Close();
            }
        }

        /// <summary>
        /// 计量单位
        /// </summary>
        /// <param name="paggingModel"></param>
        /// <returns></returns>
        public static PaggingResultModel<UnitType, BasicDataSearchModel> GetUnitTypeList(PaggingRequestModel paggingModel)
        {
            TMT_VENDOR vendor = new TMT_VENDOR();
            try
            {
                vendor.Connection.Open();

                var query = (from unit in vendor.UnitType select unit);

                query = query.OrderBy(q => q.ID);

                return DBUtility.BuildPaggingResult<UnitType, BasicDataSearchModel>(query, paggingModel, null);
            }
            finally
            {
                vendor.Connection.Close();
            }
        }


        /// <summary>
        /// 运输方式
        /// </summary>
        /// <param name="paggingModel"></param>
        /// <returns></returns>
        public static PaggingResultModel<TransportType, BasicDataSearchModel> GetTransportTypeList(PaggingRequestModel paggingModel)
        {
            TMT_VENDOR vendor = new TMT_VENDOR();
            try
            {
                vendor.Connection.Open();

                var query = (from trans in vendor.TransportType select trans);

                query = query.OrderBy(q => q.ID);

                return DBUtility.BuildPaggingResult<TransportType, BasicDataSearchModel>(query, paggingModel, null);
            }
            finally
            {
                vendor.Connection.Close();
            }
        }
    }
}
